package com.leung.grpcService;


import com.leung.protoService.HelloGrpc;
import com.leung.protoService.HelloOuterClass;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * @author 丨一
 * @version 1.0
 * @title HelloService
 * @description:
 * @date 2025/3/15 上午11:39
 */

@Slf4j
@GrpcService
public class HelloServerService extends HelloGrpc.HelloImplBase {

    @Override
    public void sayHello(HelloOuterClass.HelloRequest request, StreamObserver<HelloOuterClass.HelloReply> responseObserver) {
        System.out.println(request.getName());
        //需要给客户端响应一个回调
        //1. 构建响应体
        HelloOuterClass.HelloReply reply = HelloOuterClass.HelloReply.newBuilder().build().toBuilder().setMessage("this is return").build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}
